package com.qingke.controller;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qingke.annotation.SkipSecurityCheck;
import com.qingke.pojo.BusinessProject;
import com.qingke.pojo.Classes;
import com.qingke.pojo.DailyPerformance;
import com.qingke.pojo.Employee;
import com.qingke.pojo.EmployeeAccount;
import com.qingke.pojo.InClassTeacher;
import com.qingke.pojo.InterviewAbility;
import com.qingke.pojo.LearningEffect;
import com.qingke.pojo.LearningNote;
import com.qingke.pojo.LogRecord;
import com.qingke.pojo.OverallAppraisal;
import com.qingke.pojo.Student;
import com.qingke.service.BusinessProjectService;
import com.qingke.service.ClassService;
import com.qingke.service.DailyPerformanceService;
import com.qingke.service.EmployeeService;
import com.qingke.service.InClassTeacherService;
import com.qingke.service.InterviewAbilityService;
import com.qingke.service.LearningEffectService;
import com.qingke.service.LearningNoteService;
import com.qingke.service.LogRecordService;
import com.qingke.service.OverallAppraisalService;
import com.qingke.service.StudentService;

@Controller
@RequestMapping("/tea")
public class TeaController {
	private static Logger logger = Logger.getLogger(TeaController.class);
	private Map<String, Object> map;
	@Autowired
	private EmployeeService employeeService;
	@Autowired
	private StudentService studentService;
	@Autowired
	private ClassService classService;
	@Autowired
	private InterviewAbilityService interviewAbilityService;
	@Autowired
	private InClassTeacherService inClassTeacherService;
	@Autowired
	private DailyPerformanceService dailyPerformanceService;
	@Autowired
	private LearningEffectService learningEffectservice;
	@Autowired
	private LearningNoteService learingNoteService;
	@Autowired
	private BusinessProjectService businessProjectService;
	@Autowired
	private OverallAppraisalService overallAppraisalService;
	@Autowired
	private LogRecordService logRecordService;

	@RequestMapping("getTea")
	@SkipSecurityCheck
	@ResponseBody
	public Map getTea(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		logger.info("get tea:" + tea);
		map.put("tea", tea);
		return map;
	}

	@RequestMapping("updateTeaMessage")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateTeaMessage(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		String userId = request.getParameter("user_id");
		String email = request.getParameter("email");
		String phone = request.getParameter("phone");
		logger.info("get guiderMessage[" + "userId=" + userId + ",email=" + email + ",phone=" + phone + "]");
		if (!userId.equals(tea.getEmployeeNumber())) {
			map.put("isSame", "no");
		} else {
			tea.setEmail(email);
			tea.setPhone(phone);
			int count = employeeService.updateEmployeeByPrimaryKey(tea);
			if (count > 0) {
				map.put("update", "success");
			} else {
				map.put("update", "failed");
			}
		}
		return map;
	}

	@RequestMapping("updateTeaPassword")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateTeaPassword(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String oldPassword = request.getParameter("old_password");
		String newPassword = request.getParameter("new_password");
		String confrimPassword = request.getParameter("confirm_password");
		logger.info("get guiderPassword:old_password" + oldPassword + ",new_password=" + newPassword
				+ ",confirm_password=" + confrimPassword);
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		EmployeeAccount employeeAccount = employeeService.getEmployeeAccountById(tea.getId());
		if (!oldPassword.equals(employeeAccount.getPassword())) {
			map.put("isExsit", "false");
		} else if (!newPassword.equals(confrimPassword)) {
			map.put("equal", "false");
		} else {
			employeeAccount.setPassword(newPassword);
			int count = employeeService.updateEmployeeAccountByPrimaryKey(employeeAccount);
			if (count > 0) {
				map.put("update", "success");
			} else {
				map.put("update", "false");
			}
		}
		return map;
	}

	@RequestMapping("listPreviousStudent")
	@SkipSecurityCheck
	@ResponseBody
	public Map listPreviousStudent(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String className = request.getParameter("className");
		logger.info("get className=" + className);
		List<Student> student = new ArrayList();
		List<Student> students = studentService.listStudent();
		List<InClassTeacher> inClassTeacher = inClassTeacherService.listInClassTeacher();
		logger.info("list student:" + students);
		logger.info("list inClassTeacher:" + inClassTeacher);
		if (students != null) {
			if ("全部班级".equals(className)) {
				for (Student st : students) {
					logger.info("list student:" + st);
					if (!st.getIsDeleted()) {
						student.add(st);
					}
				}
				map.put("student", student);
			} else {
				for (Student st : students) {
					logger.info("list student:" + st);
					if (!st.getIsDeleted() && st.getClazz().getClassName().equals(className)) {
						student.add(st);
					}
				}
				map.put("student", student);
			}
			System.out.println(inClassTeacher!=null);
		} 
		if (inClassTeacher != null) {
			map.put("inClassTeacher", inClassTeacher);
		} else {
			map.put("student", "");
			map.put("inClassTeacher", "");
		}
		return map;
	}

	@RequestMapping("getStudent")
	@SkipSecurityCheck
	@ResponseBody
	public Map getStudent(HttpServletRequest request, ModelMap modelMap) {
		HttpSession se = request.getSession();
		map = new HashMap();
		String student_id = (String) request.getParameter("student_id");
		logger.info("get studentId:" + student_id);
		Student student = studentService.getStudentByStudentNumber(student_id);
		se.setAttribute("student", student);
		map.put("Student", student);
		return map;

	}

	@RequestMapping("updateStudent")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateStudent(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String studentId = (String) request.getParameter("student_id");
		String name = (String) request.getParameter("name");
		String className = (String) request.getParameter("class_name");
		String email = (String) request.getParameter("email");
		String phone = (String) request.getParameter("phone");
		String teacherName = (String) request.getParameter("teacher_name");
		HttpSession se = request.getSession();
		Student st = (Student) se.getAttribute("student");
		logger.info("get student:stduentId=" + studentId + ",name=" + name + ",className=" + className + ",email="
				+ email + ",phone=" + phone + ",teacherName=" + teacherName);
		Student student = studentService.getStudentByStudentNumber(studentId);
		Classes clazz = classService.getClassByClassName(className);
		Employee teacher = employeeService.getEmployeeByName(teacherName);
		if (!studentId.equals(st.getStudentNumber())) {
			map.put("isSame", "no");
		} else if (clazz == null) {
			map.put("isClassExist", "no");
		} else if (teacher == null) {
			map.put("isTeacherExist", "no");
		} else if (!inClassTeacherService.isTeacherInClass(teacher.getId(), clazz.getId())) {
			map.put("teacherInClass", "no");
		} else {
			student.setName(name);
			student.setClassId(clazz.getId());
			student.setEmail(email);
			student.setPhone1(phone);
			int count = studentService.updateStudentByPrimaryKey(student);
			if (count > 0) {
				map.put("success", "true");
			} else {
				map.put("success", "true");
			}
		}
		return map;
	}

	@RequestMapping("listClass")
	@SkipSecurityCheck
	@ResponseBody
	public Map listClass(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		List<Classes> clazz = classService.listClass();
		List<Classes> classes = new ArrayList();
		if (!clazz.isEmpty()) {
			for (Classes clas : clazz) {
				if (!clas.getIsDeleted()) {
					logger.info("get class=" + clas);
					classes.add(clas);
				}
			}
			map.put("classes", classes);
		} else {
			map.put("classes", "");
		}
		return map;
	}

	@RequestMapping("listStudentByClass")
	@SkipSecurityCheck
	@ResponseBody
	public Map listStudentByClass(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String className = request.getParameter("className");
		logger.info("get className=" + className);
		List<Student> student = new ArrayList();
		List<Student> students = studentService.listStudent();
		if (!students.isEmpty()) {
			if (!"".equals(className)) {
				for (Student st : students) {
					logger.info("get student=" + st + ",className=" + st.getClazz().getClassName());
					if (!st.getIsDeleted() && st.getClazz().getClassName().equals(className)) {
						student.add(st);
					}
					map.put("student", student);
				}
			} else {
				map.put("student", "");
			}
		} else {
			map.put("student", "");
		}
		return map;
	}

	@RequestMapping("listStudentDailyPerformance")
	@SkipSecurityCheck
	@ResponseBody
	public Map listStudentDailyPerformance(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String studentName = request.getParameter("student_name");
		logger.info("get studentName=" + studentName);
		Student student = studentService.getStudentByStudentName(studentName);
		if (student != null) {
			List<DailyPerformance> dailyPerformance = new ArrayList();
			List<DailyPerformance> dailyPerformances = dailyPerformanceService
					.listDailyPerformanceByStudentId(student.getId());
			if (!dailyPerformances.isEmpty()) {
				for (DailyPerformance df : dailyPerformances) {
					logger.info("list dailyPerformance:" + df);
					if (!df.getIsDeleted()) {
						dailyPerformance.add(df);
					}
				}
				map.put("dailyPerformance", dailyPerformance);
			} else {
				map.put("dailyPerformance", "");
			}
		} else {
			map.put("dailyPerformance", "");
		}
		return map;
	}

	@RequestMapping("getDailyPerformance")
	@SkipSecurityCheck
	@ResponseBody
	public Map getDailyPerformance(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get dailyPerfornmance_id=" + id);
		DailyPerformance dailyPerformance = dailyPerformanceService.getDailyPerformanceById(id);
		se.setAttribute("dailyPerformance", dailyPerformance);
		map.put("dailyPerformance", dailyPerformance);
		return map;
	}

	@RequestMapping("deleteDailyPerformance")
	@SkipSecurityCheck
	@ResponseBody
	public Map deleteDailyPerformance(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get dailyPerformance_id=" + id);
		int count = dailyPerformanceService.softDelete(id);
		if (count > 0) {
			map.put("isDelete", "success");
		} else {
			map.put("isDelete", "failed");
		}
		return map;
	}

	@RequestMapping("updateStudentDailyPerformance")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateStudentDailyPerformance(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		DailyPerformance dailyPerformance = (DailyPerformance) se.getAttribute("dailyPerformance");
		int weeks = Integer.valueOf(request.getParameter("weeks"));
		int day1 = Integer.valueOf(request.getParameter("day1"));
		int day2 = Integer.valueOf(request.getParameter("day2"));
		int day3 = Integer.valueOf(request.getParameter("day3"));
		int day4 = Integer.valueOf(request.getParameter("day4"));
		int day5 = Integer.valueOf(request.getParameter("day5"));
		int day6 = Integer.valueOf(request.getParameter("day6"));
		int day7 = Integer.valueOf(request.getParameter("day7"));
		String comment = request.getParameter("comment");
		logger.info("get weeks=" + weeks + ",day1=" + day1 + ",day2=" + day2 + ",day3=" + day3 + ",day4=" + day4
				+ ",day5=" + day5 + ",day6=" + day6 + ",day7=" + day7 + ",comment=" + comment);
		if (dailyPerformance.getWeeks() != weeks) {
			map.put("isSame", "no");
		} else {
			int total = day1 + day2 + day3 + day4 + day5 + day6 + day7;
			if (day1 != 0) {
				dailyPerformance.setDay1(day1);
			} if (day2 != 0) {
				dailyPerformance.setDay2(day2);
			}  if (day3 != 0) {
				dailyPerformance.setDay3(day3);
			}  if (day4 != 0) {
				dailyPerformance.setDay4(day4);
			}  if (day5 != 0) {
				dailyPerformance.setDay5(day5);
			}  if (day6 != 0) {
				dailyPerformance.setDay6(day6);
			}  if (day7 != 0) {
				dailyPerformance.setDay7(day7);
			}  if (!"".equals(comment)) {
				dailyPerformance.setComment(comment);
			}
			dailyPerformance.setEmployeeId(tea.getId());
			dailyPerformance.setTotal(total);
			int count = dailyPerformanceService.updateDailyPerformance(dailyPerformance);
			if (count > 0) {
				map.put("update", "success");
			} else {
				map.put("update", "failed");
			}
		}
		return map;
	}

	@RequestMapping("createStudentDailyPerformance")
	@SkipSecurityCheck
	@ResponseBody
	public Map createStudentDailyPerformance(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		String student_name = request.getParameter("student_name");
		int weeks = Integer.valueOf(request.getParameter("weeks"));
		int day1 = Integer.valueOf(request.getParameter("day1"));
		int day2 = Integer.valueOf(request.getParameter("day2"));
		int day3 = Integer.valueOf(request.getParameter("day3"));
		int day4 = Integer.valueOf(request.getParameter("day4"));
		int day5 = Integer.valueOf(request.getParameter("day5"));
		int day6 = Integer.valueOf(request.getParameter("day6"));
		int day7 = Integer.valueOf(request.getParameter("day7"));
		String comment = request.getParameter("comment");
		logger.info("get studentName=" + student_name + ",weeks=" + weeks + ",day1=" + day1 + ",day2=" + day2 + ",day3="
				+ day3 + ",day4=" + day4 + ",day5=" + day5 + ",day6=" + day6 + ",day7=" + day7 + ",comment=" + comment);
		Student student = studentService.getStudentByStudentName(student_name);
		if (student == null) {
			map.put("isExist", "no");
		} else {
			DailyPerformance dailyPerformance = new DailyPerformance();
			int total = day1 + day2 + day3 + day4 + day5 + day6 + day7;
			if (day1 != 0) {
				dailyPerformance.setDay1(day1);
			}if (day2 != 0) {
				dailyPerformance.setDay2(day2);
			}if (day3 != 0) {
				dailyPerformance.setDay3(day3);
			}if (day4 != 0) {
				dailyPerformance.setDay4(day4);
			}if (day5 != 0) {
				dailyPerformance.setDay5(day5);
			}if (day6 != 0) {
				dailyPerformance.setDay6(day6);
			}if (day7 != 0) {
				dailyPerformance.setDay7(day7);
			}if (!"".equals(comment)) {
				dailyPerformance.setComment(comment);
			}
			dailyPerformance.setStudentId(student.getId());
			dailyPerformance.setEmployeeId(tea.getId());
			dailyPerformance.setWeeks(weeks);
			dailyPerformance.setTotal(total);
			dailyPerformance.setIsDeleted(false);
			int count = dailyPerformanceService.saveDailyPerformance(dailyPerformance);
			if (count > 0) {
				map.put("create", "success");
			} else {
				map.put("create", "failed");
			}
		}
		return map;
	}

	@RequestMapping("listStudentLearningEffect")
	@SkipSecurityCheck
	@ResponseBody
	public Map listStudentLearningEffect(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String studentName = request.getParameter("student_name");
		logger.info("get studentName=" + studentName);
		Student student = studentService.getStudentByStudentName(studentName);
		if (student != null) {
			List<LearningEffect> learningEffect = new ArrayList();
			List<LearningEffect> learningEffects = learningEffectservice.listLearningEffectByStudentId(student.getId());
			if (!learningEffects.isEmpty()) {
				for (LearningEffect le : learningEffects) {
					logger.info("list learningEffect:" + le);
					if (!le.getIsDeleted()) {
						learningEffect.add(le);
					}
				}
				map.put("learningEffect", learningEffect);
			} else {
				map.put("learningEffect", "");
			}
		} else {
			map.put("learningEffect", "");
		}
		return map;
	}

	@RequestMapping("getLearningEffect")
	@SkipSecurityCheck
	@ResponseBody
	public Map getLearningEffect(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get learningEffect_id=" + id);
		LearningEffect learningEffect = learningEffectservice.getLearningEffectById(id);
		se.setAttribute("learningEffect", learningEffect);
		map.put("learningEffect", learningEffect);
		return map;
	}

	@RequestMapping("deleteLearningEffect")
	@SkipSecurityCheck
	@ResponseBody
	public Map deleteLearningEffect(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get learningEffect_id=" + id);
		int count = learningEffectservice.softdelete(id);
		if (count > 0) {
			map.put("isDelete", "success");
		} else {
			map.put("isDelete", "failed");
		}
		return map;
	}

	@RequestMapping("updateStudentLearningEffect")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateStudentLearningEffect(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		LearningEffect learningEffect = (LearningEffect) se.getAttribute("learningEffect");
		int weeks = Integer.valueOf(request.getParameter("weeks"));
		int score = Integer.valueOf(request.getParameter("score"));
		String project = request.getParameter("project");
		logger.info("get weeks=" + weeks + ",score=" + score + ",project=" + project);
		if (learningEffect.getWeeks() != weeks) {
			map.put("isSame", "no");
		} else {
			learningEffect.setEmployeeId(tea.getId());
			learningEffect.setProject(project);
			learningEffect.setScore(score);
			int count = learningEffectservice.updateLearningEffect(learningEffect);
			if (count > 0) {
				map.put("update", "success");
			} else {
				map.put("update", "failed");
			}
		}
		return map;
	}

	@RequestMapping("createStudentLearningEffect")
	@SkipSecurityCheck
	@ResponseBody
	public Map createStudentLearningEffect(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		String student_name = request.getParameter("student_name");
		int weeks= Integer.valueOf(request.getParameter("weeks"));
		int score = Integer.valueOf(request.getParameter("score"));
		String project = request.getParameter("project");
		logger.info("get studentName=" + student_name + ",weeks=" + weeks + ",score=" + score + ",project=" + project);
		Student student = studentService.getStudentByStudentName(student_name);
		if (student == null) {
			map.put("isExist", "no");
		} else {
			LearningEffect learningEffect = new LearningEffect();
			learningEffect.setStudentId(student.getId());
			learningEffect.setEmployeeId(tea.getId());
			learningEffect.setWeeks(weeks);
			learningEffect.setProject(project);
			learningEffect.setScore(score);
			learningEffect.setIsDeleted(false);
			int count = learningEffectservice.saveLearningEffect(learningEffect);
			if (count > 0) {
				map.put("create", "success");
			} else {
				map.put("create", "failed");
			}
		}
		return map;
	}

	@RequestMapping("listStudentLearningNote")
	@SkipSecurityCheck
	@ResponseBody
	public Map listStudentLearningNote(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String studentName = request.getParameter("student_name");
		logger.info("get studentName=" + studentName);
		Student student = studentService.getStudentByStudentName(studentName);
		if (student != null) {
			List<LearningNote> learningNote = new ArrayList();
			List<LearningNote> learningNotes = learingNoteService.listLearningNoteByStudentId(student.getId());
			if (!learningNotes.isEmpty()) {
				for (LearningNote ln : learningNotes) {
					logger.info("list learningNote:" + ln);
					if (!ln.getIsDeleted()) {
						learningNote.add(ln);
					}
				}
				map.put("learningNote", learningNote);
			} else {
				map.put("learningNote", "");
			}
		} else {
			map.put("learningNote", "");
		}
		return map;
	}

	@RequestMapping("getLearningNote")
	@SkipSecurityCheck
	@ResponseBody
	public Map getLearningNote(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get learningNote_id=" + id);
		LearningNote learningNote = learingNoteService.getLearningNoteById(id);
		se.setAttribute("learningNote", learningNote);
		map.put("learningNote", learningNote);
		return map;
	}

	@RequestMapping("deleteLearningNote")
	@SkipSecurityCheck
	@ResponseBody
	public Map deleteLearningNote(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get learningNote_id=" + id);
		int count = learingNoteService.softDelete(id);
		if (count > 0) {
			map.put("isDelete", "success");
		} else {
			map.put("isDelete", "failed");
		}
		return map;
	}

	@RequestMapping("updateStudentLearningNote")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateStudentLearningNote(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		LearningNote learningNote = (LearningNote) se.getAttribute("learningNote");
		int weeks = Integer.valueOf(request.getParameter("weeks"));
		int score = Integer.valueOf(request.getParameter("score"));
		String comment = request.getParameter("comment");
		logger.info("get weeks=" + weeks + ",score=" + score + ",comment=" + comment);
		if (learningNote.getWeeks() != weeks) {
			map.put("isSame", "no");
		} else {
			learningNote.setEmployeeId(tea.getId());
			learningNote.setComment(comment);
			learningNote.setScore(score);
			int count = learingNoteService.updateLearningNote(learningNote);
			if (count > 0) {
				map.put("update", "success");
			} else {
				map.put("update", "failed");
			}
		}
		return map;
	}

	@RequestMapping("createStudentLearningNote")
	@SkipSecurityCheck
	@ResponseBody
	public Map createStudentLearningNote(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		String student_name = request.getParameter("student_name");
		int weeks = Integer.valueOf(request.getParameter("weeks"));
		int score = Integer.valueOf(request.getParameter("score"));
		String comment = request.getParameter("comment");
		logger.info("get studentName=" + student_name + ",weeks=" + weeks + ",score=" + score + ",comment=" + comment);
		Student student = studentService.getStudentByStudentName(student_name);
		if (student == null) {
			map.put("isExist", "no");
		} else {
			LearningNote learningNote = new LearningNote();
			learningNote.setStudentId(student.getId());
			learningNote.setEmployeeId(tea.getId());
			learningNote.setWeeks(weeks);
			learningNote.setComment(comment);
			learningNote.setScore(score);
			learningNote.setIsDeleted(false);
			int count = learingNoteService.saveLearningNote(learningNote);
			if (count > 0) {
				map.put("create", "success");
			} else {
				map.put("create", "failed");
			}
		}
		return map;
	}

	@RequestMapping("listStudentInterviewAbility")
	@SkipSecurityCheck
	@ResponseBody
	public Map listStudentInterviewAbility(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String studentName = request.getParameter("student_name");
		logger.info("get studentName=" + studentName);
		Student student = studentService.getStudentByStudentName(studentName);
		if (student != null) {
			List<InterviewAbility> interviewAbility = new ArrayList();
			List<InterviewAbility> interviewAbilitys = interviewAbilityService
					.listInterviewAbilityByStudentId(student.getId());
			if (!interviewAbilitys.isEmpty()) {
				for (InterviewAbility ia : interviewAbilitys) {
					logger.info("list interviewAbility:" + ia);
					if (!ia.getIsDeleted()) {
						interviewAbility.add(ia);
					}
				}
				map.put("interviewAbility", interviewAbility);
			} else {
				map.put("interviewAbility", "");
			}
		} else {
			map.put("interviewAbility", "");
		}
		return map;
	}

	@RequestMapping("listStudentBusinessProject")
	@SkipSecurityCheck
	@ResponseBody
	public Map listStudentBusinessProject(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String studentName = request.getParameter("student_name");
		logger.info("get studentName=" + studentName);
		Student student = studentService.getStudentByStudentName(studentName);
		if (student != null) {
			List<BusinessProject> businessProject = new ArrayList();
			List<BusinessProject> businessProjects = businessProjectService
					.listBusinessProjectByStudentId(student.getId());
			if (!businessProjects .isEmpty()) {
				for (BusinessProject bp : businessProjects) {
					logger.info("list businessProject:" + bp);
					if (!bp.getIsDeleted()) {
						businessProject.add(bp);
					}
				}
				map.put("businessProject", businessProject);
			} else {
				map.put("businessProject", "");
			}
		} else {
			map.put("businessProject", "");
		}
		return map;
	}

	@RequestMapping("getBusinessProject")
	@SkipSecurityCheck
	@ResponseBody
	public Map getBusinessProject(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get businessProject_id=" + id);
		BusinessProject businessProject = businessProjectService.getBusinessProjectById(id);
		se.setAttribute("businessProject", businessProject);
		map.put("businessProject", businessProject);
		return map;
	}

	@RequestMapping("deleteBusinessProject")
	@SkipSecurityCheck
	@ResponseBody
	public Map deleteBusinessProject(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get businessProject_id=" + id);
		int count = businessProjectService.softDeleteBusinessProject(id);
		if (count > 0) {
			map.put("isDelete", "success");
		} else {
			map.put("isDelete", "failed");
		}
		return map;
	}

	@RequestMapping("updateStudentBusinessProject")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateStudentBusinessProject(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		BusinessProject businessProject = (BusinessProject) se.getAttribute("businessProject");
		String mission = request.getParameter("mission");
		int score = Integer.valueOf(request.getParameter("score"));
		String completionStatus = request.getParameter("comment");
		logger.info("get mission=" + mission + ",score=" + score + ",completionStatus=" + completionStatus);
		businessProject.setEmployeeId(tea.getId());
		businessProject.setMission(mission);
		businessProject.setCompletionStatus(completionStatus);
		businessProject.setScore(score);
		int count = businessProjectService.updateBusinessProjectByPrimaryKey(businessProject);
		if (count > 0) {
			map.put("update", "success");
		} else {
			map.put("update", "failed");
		}

		return map;
	}

	@RequestMapping("createStudentBusinessProject")
	@SkipSecurityCheck
	@ResponseBody
	public Map createStudentBusinessProject(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		String student_name = request.getParameter("student_name");
		String mission = request.getParameter("mission");
		int score = Integer.valueOf(request.getParameter("score"));
		String completionStatus = request.getParameter("comment");
		logger.info("get studentName=" + student_name + ",mission=" + mission + ",score=" + score + ",completionStatus="
				+ completionStatus);
		Student student = studentService.getStudentByStudentName(student_name);
		if (student == null) {
			map.put("isExist", "no");
		} else {
			BusinessProject businessProject = new BusinessProject();
			businessProject.setStudentId(student.getId());
			businessProject.setEmployeeId(tea.getId());
			businessProject.setMission(mission);
			businessProject.setCompletionStatus(completionStatus);
			businessProject.setScore(score);
			businessProject.setIsDeleted(false);
			int count = businessProjectService.saveBusinessProject(businessProject);
			if (count > 0) {
				map.put("create", "success");
			} else {
				map.put("create", "failed");
			}
		}
		return map;
	}

	@RequestMapping("listStudentOverallAppraisal")
	@SkipSecurityCheck
	@ResponseBody
	public Map listStudentOverallAppraisal(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		String studentName = request.getParameter("student_name");
		logger.info("get studentName=" + studentName);
		Student student = studentService.getStudentByStudentName(studentName);
		if (student != null) {
			List<OverallAppraisal> overallAppraisal = new ArrayList();
			List<OverallAppraisal> overallAppraisals = overallAppraisalService
					.listOverallAppraisalByStudentId(student.getId());
			if (!overallAppraisals.isEmpty()) {
				for (OverallAppraisal oa : overallAppraisals) {
					logger.info("list overallAppraisal:" + oa);
					if (!oa.getIsDeleted()) {
						overallAppraisal.add(oa);
					}
				}
				map.put("overallAppraisal", overallAppraisal);
				map.put("student", student);
			} else {
				map.put("overallAppraisal", "");
				map.put("student", student);
			}
		} else {
			map.put("overallAppraisal", "");
			map.put("student", "");
		}
		return map;
	}

	/*@RequestMapping("getOverallAppraisal")
	@SkipSecurityCheck
	@ResponseBody
	public Map getOverallAppraisal(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get overallAppraisal_id=" + id);
		OverallAppraisal overallAppraisal = overallAppraisalService.getOverallAppraisalById(id);
		se.setAttribute("overallAppraisal", overallAppraisal);
		map.put("overallAppraisal", overallAppraisal);
		return map;
	}*/

/*	@RequestMapping("deleteOverallAppraisal")
	@SkipSecurityCheck
	@ResponseBody
	public Map deleteOverallAppraisal(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get overallAppraisal_id=" + id);
		int count = overallAppraisalService.softDelete(id);
		if (count > 0) {
			map.put("isDelete", "success");
		} else {
			map.put("isDelete", "failed");
		}
		return map;
	}*/

	@RequestMapping("updateStudentOverallAppraisal")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateStudentOverallAppraisal(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get overallAppraisal_id=" + id);
		OverallAppraisal overallAppraisal = overallAppraisalService.getOverallAppraisalById(id);
		int totalScore = Integer.valueOf(request.getParameter("totalscore"));
		String comment = request.getParameter("comment");
		logger.info("get totalScore=" + totalScore + ",comment=" + comment+",tea="+tea);
		overallAppraisal.setEmployeeId(tea.getId());
		overallAppraisal.setComment(comment);
		overallAppraisal.setTotalScore(totalScore);
		int count = overallAppraisalService.updateOverallAppraisal(overallAppraisal);
		if (count > 0) {
			map.put("update", "success");
		} else {
			map.put("update", "failed");
		}

		return map;
	}

	@RequestMapping("createStudentOverallAppraisal")
	@SkipSecurityCheck
	@ResponseBody
	public Map createStudentOverallAppraisal(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		String student_name = request.getParameter("student_name");
		int totalScore = Integer.valueOf(request.getParameter("totalscore"));
		String comment = request.getParameter("comment");
		logger.info("get studentName=" + student_name + ",totalScore=" + totalScore + ",comment=" + comment);
		Student student = studentService.getStudentByStudentName(student_name);
		if (student == null) {
			map.put("isExist", "no");
		} else {
			OverallAppraisal overallAppraisal = new OverallAppraisal();
			overallAppraisal.setStudentId(student.getId());
			overallAppraisal.setEmployeeId(tea.getId());
			overallAppraisal.setComment(comment);
			overallAppraisal.setTotalScore(totalScore);
			overallAppraisal.setIsDeleted(false);
			int count = overallAppraisalService.saveOverallAppraisal(overallAppraisal);
			if (count > 0) {
				map.put("create", "success");
			} else {
				map.put("create", "failed");
			}
		}
		return map;
	}

	@RequestMapping("listLogRecord")
	@SkipSecurityCheck
	@ResponseBody
	public Map listLogRecord(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se=request.getSession();
		Employee tea =(Employee)se.getAttribute("user"); 
		List<LogRecord> logRecord = new ArrayList();
		List<LogRecord> logRecords = logRecordService.listLogRecordByEmployeeId(tea.getId());
		if (!logRecords.isEmpty()) {
			for (LogRecord lr : logRecords) {
				logger.info("list logRecord:" + lr);
				if (!lr.getIsDeleted()) {
					logRecord.add(lr);
				}
			}
			map.put("logRecord", logRecord);
		} else {
			map.put("logRecord", "");
		}
		return map;

	}

	@RequestMapping("getLogRecord")
	@SkipSecurityCheck
	@ResponseBody
	public Map getLogRecord(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get logRecord_id=" + id);
		LogRecord logRecord = logRecordService.getLogRecordById(id);
		se.setAttribute("logRecord", logRecord);
		map.put("logRecord", logRecord);
		return map;
	}

	@RequestMapping("deleteLogRecord")
	@SkipSecurityCheck
	@ResponseBody
	public Map deleteLogRecord(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		int id = Integer.valueOf(request.getParameter("id"));
		logger.info("get logRecord_id=" + id);
		int count = logRecordService.softDelete(id);
		if (count > 0) {
			map.put("isDelete", "success");
		} else {
			map.put("isDelete", "failed");
		}
		return map;
	}

	@RequestMapping("updateLogRecord")
	@SkipSecurityCheck
	@ResponseBody
	public Map updateLogRecord(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		LogRecord logRecord = (LogRecord) se.getAttribute("logRecord");
		String content = request.getParameter("content");
		logger.info("get content=" + content);
		logRecord.setEmployeeId(tea.getId());
		logRecord.setContent(content);
		int count = logRecordService.updateLogRecord(logRecord);
		if (count > 0) {
			map.put("update", "success");
		} else {
			map.put("update", "failed");
		}

		return map;
	}

	@RequestMapping("createLogRecord")
	@SkipSecurityCheck
	@ResponseBody
	public Map createLogRecord(HttpServletRequest request, ModelMap modelMap) {
		map = new HashMap();
		HttpSession se = request.getSession();
		Employee tea = (Employee) se.getAttribute("user");
		String content = request.getParameter("content");
		Date date = new Date();
		Timestamp timestamp = new Timestamp(date.getTime());
		logger.info("get content=" + content + ",date=" + timestamp);
		LogRecord logRecord = new LogRecord();
		logRecord.setContent(content);
		logRecord.setDate(timestamp);
		logRecord.setEmployeeId(tea.getId());
		logRecord.setIsDeleted(false);
		int count = logRecordService.saveLogRecord(logRecord);
		if (count > 0) {
			map.put("create", "success");
		} else {
			map.put("create", "failed");
		}
		return map;
	}
}
